/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.common.biz.event;

import com.comac.ins.common.biz.domain.db.BizEventInfo;
import com.comac.ins.common.biz.domain.model.BizEvent;
import org.apache.commons.lang3.StringUtils;

import java.text.MessageFormat;

/**
 * BizEventUtil
 *
 * @author zhanghongyi
 * @date 2025-01-24
 * @description BizEventUtil
 */
public class BizEventUtil {

    private static final ThreadLocal<BizEvent<?>> threadLocalEvent = new ThreadLocal<>();

    protected static BizEvent<?> getEvent() {
        return threadLocalEvent.get();
    }
    protected static void setEvent(BizEvent<?> event) {
        threadLocalEvent.set(event);
    }
    protected static void removeEvent() {
        threadLocalEvent.remove();
    }
    public static void setCurrentMsg(BizEventInfo eventInfo, String currentMsg){
        eventInfo.setCurrentInfo(currentMsg);
        if(StringUtils.isNotBlank(eventInfo.getHistoryInfo())){
            eventInfo.setHistoryInfo(MessageFormat.format("{0}<br/>\n{1}",currentMsg,eventInfo.getHistoryInfo()));
        } else {
            eventInfo.setHistoryInfo(currentMsg);
        }
    }
}
